﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace kwzx
{
    public partial class k_ping : Form
    {
        public k_ping()
        {
            InitializeComponent();
        }

        private void user_pringBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.user_pringBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.dataSet1);

        }

        private void k_ping_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSet1.user_pring”中。您可以根据需要移动或删除它。
            this.user_pringTableAdapter.FillBy_照片名称(this.dataSet1.user_pring);

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            DataSet1TableAdapters.user_pringTableAdapter userpring = new DataSet1TableAdapters.user_pringTableAdapter();

            DataSet1TableAdapters.V_user_kpingTableAdapter vuserkping = new DataSet1TableAdapters.V_user_kpingTableAdapter();
            int leng = vuserkping.GetDataBy_22().Rows.Count;
            foreach (DataSet1.V_user_kpingRow a in vuserkping.GetDataBy_22().Rows)
            {
                string 有问题身份身号 = "210403196909103333,210402196301202978,321088196904216134,530322196501101922,210404196508242128,210403196210172132,210402196409130216";
                if (有问题身份身号.Contains(a.sfzh))
                {

                    continue;
                }
                string gz = a.MC;
                if (gz == "后勤（文秘、司机、厨师、保安、保洁、绿化）")
                {
                    gz = "后勤";
                }
                string zpname = a.ZP;
                zpname = zpname.Replace("~/admin/ftp/DBFZSPersonImg/", "");
                string fileName = @"C:\门禁信息\ftp\DBFZSPersonImg\" + zpname;
                string yy = @"C:\门禁信息\打印照片\" + zpname;
                if (a.UBY != "-1")
                {
                    if (System.IO.File.Exists(fileName))
                    {

                        System.IO.File.Copy(fileName, yy);

                    }
                    else
                    {
                        zpname = "";
                    }

                  userpring.Insert(a.user_id, a.DEPT_id, a.XM, a.ZSXM, a.UBY, a.sfzh, a.rybh, a.ZP, a.gz, a.JC, gz, a.gsbmmc, zpname, DateTime.Now);
                }

            }
            MessageBox.Show("OK");
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application excel;
            try
            {
                excel = new Microsoft.Office.Interop.Excel.Application(); //开启excel

            }
            catch (Exception vv)
            {
                MessageBox.Show("起用失败或是没有安装EXCL" + vv.Message.ToString());

                return;
            }


            if (excel == null)
            {
                MessageBox.Show("起用失败或是没有安装EXCL");

                return;
            }
            excel.Application.Workbooks.Add(true);
            Microsoft.Office.Interop.Excel.Sheets ExcelSheets = excel.Worksheets; //建立一个新的工作       
            int r = 0;
            int call = 0;
            string kk = "";
            string ll = "";
            for (int i = 0; i < dataGridView2.Columns.Count - 1; i++)
            {
                if ((bool)dataGridView2.Columns[i].Visible)
                {
                    excel.Cells[1, i + 1 - r] = dataGridView2.Columns[i].HeaderText.ToString();// +dataGridView2.Columns[i].DataPropertyName + "[" + dataGridView2.Columns[i].ValueType.Name.ToString() + "]"; ;
                    call = i + 1 - r;

                }
                else
                {
                    ++r;
                }
            }
            r = 0;
            for (int n = 0; n < dataGridView2.Rows.Count; n++)
            {
                r = 0;
                for (int i = 0; i < dataGridView2.Columns.Count; i++)
                {
                    if ((bool)dataGridView2.Columns[i].Visible)
                    {
                        excel.Cells[n + 2, i + 1 - r] = dataGridView2.Rows[n].Cells[i].Value.ToString();

                    }
                    else
                    {
                        ++r;
                    }
                }

            }
            excel.Visible = true;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            DataSet1TableAdapters.user_pringTableAdapter userpring = new DataSet1TableAdapters.user_pringTableAdapter();
            int ww = userpring.GetData().Rows.Count;

            string name = "";
            foreach (DataSet1.user_pringRow a in userpring.GetData().Rows)
            {
                DataTable tb = userpring.GetDataBy_name(a.姓名);
                if (tb.Rows.Count > 1)
                {
                    name += a.姓名 + ",";
                }
            }
            MessageBox.Show(name);
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            DataSet1TableAdapters.user_pringTableAdapter userpring = new DataSet1TableAdapters.user_pringTableAdapter();
            int ee = userpring.GetDataBy1null().Rows.Count;

            foreach (DataSet1.user_pringRow a in userpring.GetDataBy1null().Rows)
            {
               
                string zpname = a.ZP;
                zpname = zpname.Replace("~/admin/ftp/DBFZSPersonImg/", "");
                string fileName = @"C:\门禁信息\打印照片\" + zpname;
                string yy = @"C:\门禁信息\打印改名\" + a.姓名 + ".jpg";
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.File.Copy(fileName, yy);
                    userpring.UpdateQuery_照片名称(a.姓名 + ".jpg", a.id);
                }
                else
                {
                    zpname = "";
                }
                   
            }
            MessageBox.Show("OK");
        }
    }
}
